package com.saxon.shuttle.actuator.controller;

import com.google.common.collect.Lists;
import com.saxon.shuttle.actuator.entity.User;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDate;
import java.util.List;

@Api
@RefreshScope
@RestController
@RequestMapping("/api/v1/users")
public class UserController {

    private List<User> users = Lists.newArrayList(
            new User(1, "谭浩强", 100, LocalDate.now()),
            new User(2, "严蔚敏", 120, LocalDate.now()),
            new User(3, "谭浩强", 100, LocalDate.now()),
            new User(4, "James Gosling", 150, LocalDate.now()),
            new User(6, "Doug Lea", 150, LocalDate.now())
    );
    @Value("${server.port}")
    private String port;
    @Value("${foo}")
    private String foo;

    @GetMapping("/")
    public List<User> list() {
        return users;
    }

    @RequestMapping("/hi")
    public String home(@RequestParam String name) {
        return "hi " + name + ",i am from port:" + port;
    }

    @RequestMapping(value = "/config")
    public String config() {
        return foo;
    }
}
